<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class Config
 * Desc  系统配置
 * Create on 2024/11/26 8:39
 * Create by wangyafang
 */

namespace app\api\controller\wddj;


use app\common\controller\Api;

class Config extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\api\model\wddj\Config();
    }

    /**
     * Desc 系统配置
     * Create on 2024/11/26 8:41
     * Create by wangyafang
     */
    public function config()
    {
        if (!$this->request->isGet()) {
            $this->error('请求类型错误');
        }

        $configObj = $this->model
            ->where('id', 1)
            ->field('applet_name,theme_colors,share_title,share_image,
            real_name_authentication_status,login_img,
            applet_record_number,tencent_map_web_service_key,websocket_port')
            ->find();

        $configArray = $configObj->toArray();

        $configArray['share_image'] = wddj_full_url($configArray['share_image']);
        $configArray['login_img'] = wddj_full_url($configArray['login_img']);
        $configArray['websocket_port'] = $this->request->host().':'.$configArray['websocket_port'];

        $data = array_merge($configArray,array(
            'version'=>'V1.0.0',
        ));
        $url = cdnurl('', true);
        if (!wddj_is_url($url)) {
            $url = request()->domain() . $url;
        }
        $data['domain'] = $url;

        $this->success('请求成功', $data);
    }

    /**
     * Desc 驾照类型
     * Create on 2024/11/27 10:28
     * Create by wangyafang
     */
    public function driver_license_type()
    {
        $data = array(
            'A1',
            'A2',
            'A3',
            'B1',
            'B2',
            'C1',
            'C2',
        );

        $this->success('请求成功',$data);
    }
    /**
     * Desc 驾照类型
     * Create on 2024/11/27 10:28
     * Create by wangyafang
     */
    public function trailer_license_type()
    {
        $data = array(
            'A1',
            'A2',
            'A3',
            'B1',
            'B2',
            'C1',
        );

        $this->success('请求成功',$data);
    }
    /**
     * Desc 取消订单选项
     * Create on 2024/12/12 8:56
     * Create by wangyafang
     */
    public function cancel_order_option()
    {
        $cancel_order_option = $this->model->where('id',1)->value('cancel_order_option');

        $data = json_decode($cancel_order_option, true);
        $this->success('请求成功',$data);
    }
    
    /**
     * Desc 常用语
     * Create on 2024/12/14 14:06
     * Create by wangyafang
     */
    public function common_phrases()
    {
        if(!$this->request->isGet()) {
            $this->error('请求类型错误');
        }
        $type = $this->request->get('type');
        $field = $type == 1 ? 'user_common_phrases' : 'driver_common_phrases';
        $common_phrases = $this->model->where('id',1)->value($field);

        $data = json_decode($common_phrases, true);
        $this->success('请求成功',$data);
    }
}



 